using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using GameCore;

namespace GameObject
{
    public class Sprite
    {
        public Sprite(float _xinput, float _yinput,int _winput,int _hinput, Texture2D[] arrTexture2D)
        {
            _x = _xinput;
            _y = _yinput;
            _width = _winput;
            _height = _hinput;
            _arrTexture2D = arrTexture2D;
            _iSelectedIndex = 0;
        }

        protected float _x;

        public virtual float x
        {
            get { return _x; }
            set { _x = value; }
        }

        protected float _y;

        public virtual float y
        {
            get { return _y; }
            set { _y = value; }
        }
        int _width;

        public int Width
        {
            get { return _width; }
            set { _width = value; }
        }
        int _height;

        public int Height
        {
            get { return _height; }
            set { _height = value; }
        }

        protected Texture2D[] _arrTexture2D;

        public virtual Texture2D[] arrTexture2D
        {
            get { return _arrTexture2D; }
            set
            {
                _arrTexture2D = value;
                _ntextture2D = _arrTexture2D.Length;
            }
        }

        protected int _ntextture2D;

        public virtual int ntextture2D
        {
            get { return _ntextture2D; }
            set { _ntextture2D = value; }
        }

        private int _iSelectedIndex;

        public virtual int iSelectedIndex
        {
            get { return _iSelectedIndex; }
            set { _iSelectedIndex = value; }
        }

        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();

            spriteBatch.Draw(
                _arrTexture2D[_iSelectedIndex],new Rectangle(
                    (int)(_x / 1f - ViewFrame.window.X),
                    (int)(_y / 1f - ViewFrame.window.Y),
                    this._width,
                    this._height),
                
                new Rectangle(
                    0, 0,
                    _arrTexture2D[_iSelectedIndex].Width,
                    _arrTexture2D[_iSelectedIndex].Height),
                Color.White);

            spriteBatch.End();
        }

        public virtual void Update(GameTime gameTime, int tt_index, float x, float y, int wi, int he)
        {
            if ((0 <= tt_index) && (tt_index < _arrTexture2D.Count<Texture2D>()))
                _iSelectedIndex = tt_index;
            _x = x;
            _y = y;
            _width = wi;
            _height = he;
        }
        public Sprite Clone()
        {
            return new Sprite(_x,_y,_width,_height,_arrTexture2D);
        }
    }
}
